package cn.house.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import cn.house.entity.SystemUser;

public class BCryptUtils {

	private static PasswordEncoder passwordEncoder = SpringUtil.getBean(BCryptPasswordEncoder.class);

	public static String encoder(String pass) {
		return passwordEncoder.encode(pass);
	}

	public static void encoder(SystemUser user) {
		if (StringUtils.isBlank(user.getPassword())) {
			user.setPassword(user.getUsername());
		}
		user.setPassword(passwordEncoder.encode(user.getPassword()));
	}

	public static Boolean matches(String p1, String p2) {
		return passwordEncoder.matches(p1, p2);
	}
}
